package com.ruoyi.show.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.show.domain.CategoryStats;
import com.ruoyi.show.service.ICategoryStatsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 书籍种类数据Controller
 * 
 * @author ruoyi
 * @date 2025-09-08
 */
@RestController
@RequestMapping("/show/category")
public class CategoryStatsController extends BaseController
{
    @Autowired
    private ICategoryStatsService categoryStatsService;

    /**
     * 查询书籍种类数据列表
     */
    @PreAuthorize("@ss.hasPermi('show:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(CategoryStats categoryStats)
    {
        startPage();
        List<CategoryStats> list = categoryStatsService.selectCategoryStatsList(categoryStats);
        return getDataTable(list);
    }

    /**
     * 导出书籍种类数据列表
     */
    @PreAuthorize("@ss.hasPermi('show:category:export')")
    @Log(title = "书籍种类数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CategoryStats categoryStats)
    {
        List<CategoryStats> list = categoryStatsService.selectCategoryStatsList(categoryStats);
        ExcelUtil<CategoryStats> util = new ExcelUtil<CategoryStats>(CategoryStats.class);
        util.exportExcel(response, list, "书籍种类数据数据");
    }

    /**
     * 获取书籍种类数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('show:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(categoryStatsService.selectCategoryStatsById(id));
    }

    /**
     * 新增书籍种类数据
     */
    @PreAuthorize("@ss.hasPermi('show:category:add')")
    @Log(title = "书籍种类数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CategoryStats categoryStats)
    {
        return toAjax(categoryStatsService.insertCategoryStats(categoryStats));
    }

    /**
     * 修改书籍种类数据
     */
    @PreAuthorize("@ss.hasPermi('show:category:edit')")
    @Log(title = "书籍种类数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CategoryStats categoryStats)
    {
        return toAjax(categoryStatsService.updateCategoryStats(categoryStats));
    }

    /**
     * 删除书籍种类数据
     */
    @PreAuthorize("@ss.hasPermi('show:category:remove')")
    @Log(title = "书籍种类数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(categoryStatsService.deleteCategoryStatsByIds(ids));
    }
}
